<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>Synchronous mode</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="generator" content="Doc-O-Matic" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <link rel="STYLESHEET" href="default.css" type="text/css" />

<script type="text/javascript" src="scripts.js"></script>
</head>
<body class="Element700" onload="onBodyLoadEx('frames.html', 'topic', '00140.html');" onmousedown="onBodyMouseDown();">

<!-- Begin Popups -->

<!-- End Popups -->

<!-- Begin Page Header -->
<div class="Element710" id="areafixed">
<div class="Element94">
<a href="00007.html" target="topic">Driver Libraries Help</a> &gt; <a href="00137.html" target="topic">SPI Driver Library Help</a> &gt; <a href="00142.html" target="topic">Using the Library</a> &gt; <a href="00140.html" target="topic">Synchronous mode</a></div>
<div class="Element92">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="25%">
<div class="Element1">
MPLAB Harmony Core Help</div>
</td><td width="25%">
<div class="Element2">
<a href="contents.html" target="tocidx">Contents</a> | <a href="00007.html" target="topic">Home</a></div>
</td><td width="25%">
<div class="Element90">
<a href="00128.html" target="topic">Previous</a> | <a href="00142.html" target="topic">Up</a> | <a href="00131.html" target="topic">Next</a></div>
</td><td width="25%">
<div class="Element96">
<a href="mailto:docerrors@microchip.com&subject=MPLAB Harmony Documentation Feedback (Topic ID: DRV SPI Synchronous Mode Topic Title: Synchronous mode)&body=Thank you for your feedback! Please include a description of your feedback, and indicate whether you are reporting an an error in the documentation or an enhancement.">Documentation Feedback</a><br> <a href="http://support.microchip.com" target="_blank">Microchip Support</a></div>
</td></tr></table><div class="Element5">
Synchronous mode</div>
</div>
</div>

<!-- End Page Header -->

<!-- Begin Client Area -->
<div class="Element720" id="areascroll">
<div class="Element721">

<!-- Begin Page Content -->
<a name="PageContent"></a><div class="Element58">
<a name="4465736372697074696F6E"></a><div class="Element11">
<div class="Element10">
<p class="Element10">
Synchronous mode of SPI driver allows user to use the library in blocking manner. This mode is supported only in RTOS environment. Transfer APIs of this mode block until transfer is complete and return true or false depending on transfer status. Here is the example of SPI write in synchronous mode:&nbsp;</p>
<p class="Element10">
&nbsp;</p><div class="Element13"><div class="Element12"><pre class="Element12">    DRV_SPI_TRANSFER_SETUP  setup;
    DRV_HANDLE              drvSPIHandle;
    uint8_t                 writeData[] = &quot;SPI Driver Async Mode&quot;;

    <i><span style="color: #008000">// SPI Driver Initialization is done in MHC generated code</span></i>

    <i><span style="color: #008000">/* Setup structure for SPI transfer */</span></i>
    setup.baudRateInHz = 600000;
    setup.clockPhase = DRV_SPI_CLOCK_PHASE_VALID_LEADING_EDGE;
    setup.clockPolarity = DRV_SPI_CLOCK_POLARITY_IDLE_LOW;
    setup.dataBits = DRV_SPI_DATA_BITS_8;
    setup.chipSelect = SYS_PORT_PIN_PD16;
    setup.csPolarity = DRV_SPI_CS_POLARITY_ACTIVE_LOW;

    <i><span style="color: #008000">/* Open the SPI Driver*/</span></i>
    drvSPIHandle = DRV_SPI_Open( DRV_SPI_INDEX_0, DRV_IO_INTENT_READWRITE);

    <strong><span style="color: #000080">if</span></strong>(drvSPIHandle != DRV_HANDLE_INVALID)
    {
        <strong><span style="color: #000080">if</span></strong>(DRV_SPI_TransferSetup(drvSPIHandle, &amp;setup) == <strong><span style="color: #000080">true</span></strong>)
        {
            <i><span style="color: #008000">// setup is successful</span></i>
        }
    }

    <strong><span style="color: #000080">if</span></strong>(DRV_SPI_WriteTransfer(drvSPIHandle, &amp;writeData, <strong><span style="color: #000080">sizeof</span></strong>(writeData)) == <strong><span style="color: #000080">true</span></strong>)
    {
        <i><span style="color: #008000">// transfer is completed successfully</span></i>
    }</pre></div></div>
</div>
</div>
</div>
<!-- End Page Content -->

<!-- Begin Page Footer -->
<div class="Element95">
<a href="00007.html" target="topic">Driver Libraries Help</a> &gt; <a href="00137.html" target="topic">SPI Driver Library Help</a> &gt; <a href="00142.html" target="topic">Using the Library</a> &gt; <a href="00140.html" target="topic">Synchronous mode</a></div>
<div class="Element93">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="25%">
<div class="Element3">
MPLAB Harmony Core Help</div>
</td><td width="25%">
<div class="Element4">
<a href="contents.html" target="tocidx">Contents</a> | <a href="00007.html" target="topic">Home</a></div>
</td><td width="25%">
<div class="Element91">
<a href="00128.html" target="topic">Previous</a> | <a href="00142.html" target="topic">Up</a> | <a href="00131.html" target="topic">Next</a></div>
</td><td width="25%">
<div class="Element97">
<a href="mailto:docerrors@microchip.com&subject=MPLAB Harmony Documentation Feedback (Topic ID: DRV SPI Synchronous Mode Topic Title: Synchronous mode)&body=Thank you for your feedback! Please include a description of your feedback, and indicate whether you are reporting an an error in the documentation or an enhancement.">Documentation Feedback</a><br> <a href="http://support.microchip.com" target="_blank">Microchip Support</a></div>
</td></tr></table></div>

<!-- End Page Footer -->
</div>
</div>

<!-- End Client Area -->
</body></html>